package io.renren.modules.generator.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.util.StringUtils;
import com.aliyun.oss.common.utils.DateUtil;

import io.renren.modules.generator.dao.GivingboxinfoDao;
import io.renren.modules.generator.entity.GivingboxinfoEntity;
import io.renren.modules.generator.entity.GuardianEntity;
import io.renren.modules.generator.service.GivingboxinfoService;
import io.renren.modules.generator.service.GuardianService;
import io.renren.util.UUIDUtil;



@Service("givingboxinfoService")
public class GivingboxinfoServiceImpl extends BaseServiceImpl implements GivingboxinfoService {
	
	@Autowired
	private GuardianService guardianService;
	
	@Override
	public GivingboxinfoEntity queryObject(String giveno) {
		GivingboxinfoEntity givingboxinfoEntity = givingboxinfoDao.queryObject(giveno); 
		if(null != givingboxinfoEntity && null != givingboxinfoEntity.getGiveperno()){
			GuardianEntity guardianEntity = new GuardianEntity();
			guardianEntity = guardianService.queryObject(givingboxinfoEntity.getGiveperno());
			if( null != guardianEntity && !StringUtils.isEmpty(guardianEntity.getName())) {
				givingboxinfoEntity.setGivepername(guardianEntity.getName());
			}
		}
		return givingboxinfoEntity;
	}
	
	@Override
	public List<GivingboxinfoEntity> queryList(Map<String, Object> map){
		return givingboxinfoDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return givingboxinfoDao.queryTotal(map);
	}
	
	@Override
	public void save(GivingboxinfoEntity givingboxinfo){
		givingboxinfo.setGiveno(UUIDUtil.getOrderIdByUUId());
		givingboxinfoDao.save(givingboxinfo);
	}
	
	@Override
	public void update(GivingboxinfoEntity givingboxinfo){
		givingboxinfoDao.update(givingboxinfo);
	}
	
	@Override
	public void delete(String giveno){
		givingboxinfoDao.delete(giveno);
	}
	
	@Override
	public void deleteBatch(String[] givenos){
		givingboxinfoDao.deleteBatch(givenos);
	}

	@Override
	public List<GivingboxinfoEntity> findAllGivingboxinfo() {
		return givingboxinfoDao.findAllGivingboxinfo();
	}
	
}
